package utils

import "regexp"

// IsValidPhone 验证手机号
func IsValidPhone(phone string) bool {
	pattern := `^1[3-9]\d{9}$`
	re := regexp.MustCompile(pattern)
	return re.MatchString(phone)
}

// IsValidIDCard 验证身份证号码
func IsValidIDCard(idCard string) bool {
	pattern := `^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[0-9Xx]$`
	re := regexp.MustCompile(pattern)
	return re.MatchString(idCard)
}

// IsValidEmail 验证邮箱
func IsValidEmail(email string) bool {
	pattern := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
	re := regexp.MustCompile(pattern)
	return re.MatchString(email)
}

// IsValidPassword 验证密码强度 (密码长度8-16，至少要有大写字母、小写字母、数字)
func IsValidPassword(password string) bool {
	pattern := `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\p{L}\p{N}\p{P}\p{S}]{8,16}$`
	re := regexp.MustCompile(pattern)
	return re.MatchString(password)
}

// IsValidURL 验证 URL
func IsValidURL(url string) bool {
	pattern := `^(https?://)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$`
	re := regexp.MustCompile(pattern)
	return re.MatchString(url)
}

// IsValidDate 验证日期（YYYY-MM-DD 格式）
func IsValidDate(date string) bool {
	pattern := `^(19|20)\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$`
	re := regexp.MustCompile(pattern)
	return re.MatchString(date)
}
